﻿function closewindow()
    {
        self.close();
    }
    
//    function setvalue(controlid,storagevalue,displayvalue)
//    {
//    //alert(displayvalue);
//    //alert(storagevalue);
//        if(top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_txt_"+controlid)!=null)
//        {
//            
//            //displayvalue = displayvalue.Replace(/'/,"''");
//            top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_txt_"+controlid).value = displayvalue;  
//        }
//        if(top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_"+controlid)!=null)
//        {
//            top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_"+controlid).value = storagevalue;
//        }
//    }
    function setvalue(hiddenfieldid,textboxid,storagevalue,displayvalue)
    {
//    alert(displayvalue);
//    alert(storagevalue);
//    alert(textboxid);
//    alert(hiddenfieldid);
//    alert(top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_"+textboxid));
//    alert(top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_"+hiddenfieldid));
        if(top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_"+textboxid)!=null)
        {
            //alert(displayvalue);
            //alert(storagevalue);
            //var dvalue;
            displayvalue = displayvalue.replace(/~RDQ~/g,"\"");
            displayvalue = displayvalue.replace(/~RDS~/g,"\\");
            //alert(displayvalue);
            //displayvalue = displayvalue.replace(/'/,"''");
            top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_"+textboxid).value = displayvalue;  
            try
            {
            //alert(top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_"+textboxid).focus());
                top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_"+textboxid).focus();
            }
            catch(ex)
            {
                
            }
            
        }
        if(top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_"+hiddenfieldid)!=null)
        {
            storagevalue = storagevalue.replace(/~RDQ~/g,"\"");
            storagevalue = storagevalue.replace(/~RDS~/g,"\\");
            top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_"+hiddenfieldid).value = storagevalue;
        }
    }
    
    function SetValueForDDE(control_id,storagevalue,displayvalue)
    {
        if(top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_"+control_id)!=null)
        {
        
            //alert("controlfound");
            var valuefound = "0";
            Control = top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_"+control_id);
            //alert(Control.type);
            if(top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_"+control_id).type=="select-one")
            {
            
            if(top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_hf_DDE_DV_"+control_id)!=null)
            {
                top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_hf_DDE_DV_"+control_id).value =displayvalue ;
            }
            
            for(var j=0;j<Control.options.length;j++)
            {
                if(Control.options[j].value==storagevalue)
                {
                   //alert("Storage value found");
                   valuefound="1";
                   Control.options[j].selected = true;
                   break;
                }
            }
            //alert(valuefound);
            if(valuefound=="0")
            {
                var opt = window.opener.document.createElement("option");
                opt.text = displayvalue;
	            opt.value = storagevalue;
	            //alert(displayvalue);
	            //alert(storagevalue);
                top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_"+control_id).options.add(opt,0);
                top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_"+control_id).selectedIndex = 0;
            }
                                
//                for(var i = 1; i < top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_"+control_id).options.length; i++) 
//		        {
//			        if(top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_"+control_id).options[i].value == storagevalue) 
//			        {
//				        top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_"+control_id).selectedIndex = i;
//				        break;
//			        }
//		        }
            }
        }
    }
    
    function SetDDEValue(Control,storagevalue,displayvalue)
                    {
                        if(Control!=null)
                        {
                            //alert("SetDDEValue");
                            var opt = document.createElement("option");
                            opt.text = "test";
	                        opt.value = "test33";
	                        Control.options.add(opt);
                        }
                    }
    
    
   
    function assignsearchvalue()
    {
        alert(window.location.search);
    }
function SetSearchValue()
{
    //alert('called');
     
    var controlid = document.getElementById("hfcontrolid").value;
    //alert(controlid);
    if(top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_txt_"+controlid)!=null)
    {
        //alert('going to assign');
        if(document.getElementById("txtsearch")!=null)
        {
        //alert(top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_txt_"+controlid).value);
            document.getElementById("txtsearch").value = top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_txt_"+controlid).value;
            //document.form1.submit();
        }
        
    }

}

function resubmitform()
{
//if(document.getElementById("txtsearch").value!="")
//{
//    alert(document.getElementById("txtsearch").value);
//    if(document.getElementById("hfsearchdata").value=="")
//    {
//        alert(document.getElementById("hfsearchdata").value);
//        
//       
//       
//        
//       // alert('test');
//        document.form1.submit();
//        //document.getElementById("")
//    }
//}

    if(document.getElementById("hfsearchdata")!=null)
    {
      if(document.getElementById("hfsearchdata").value=="")
      {
       // alert('Going to set data');
        //document.getElementById("hfsearchdata").value = "top.window.opener.document.getElementById("ctl00_ContentPlaceHolder3_txt_"+controlid).value;";
        document.form1.submit();
        
      }
      
    }
}